package com.lzh.chatnote.chat.service.adapter;

import cn.hutool.extra.spring.SpringUtil;
import com.lzh.chatnote.chat.domain.vo.response.group.GroupQueryResp;
import com.lzh.chatnote.user.domain.entity.User;
import com.lzh.chatnote.user.service.cache.UserRoleCache;
import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class GroupMemberAdapter {
    public static List<GroupQueryResp> toGroupResp(List<User> userList) {
        UserRoleCache userRoleCache = SpringUtil.getBean(UserRoleCache.class);
        return userList.stream().map(user -> GroupQueryResp.builder()
                .uid(user.getId())
                .activeStatus(user.getActiveStatus())
                .roleIds(userRoleCache.queryRoleByUid(user.getId()))
                .lastOptTime(user.getLastOptTime())
                .build()).collect(Collectors.toList());
    }
}
